import requests

from commom.get_new_auth import get_new_token


class bumen():

    @classmethod
    def add_bumen(cls, name, code):
        autu = get_new_token()
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/company/department",
                             headers={"Content-Type": "application/json", "Authorization":autu },
                             json={"name": name, "code": code})
        global a
        a = resp.json()["data"]["id"]

        return resp

    @classmethod
    def put_bumen(cls, name, code):
        autu = get_new_token()
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/company/department/" + a,
                            headers={"Content-Type": "application/json", "Authorization": autu },
                            json={"name": name, "code": code})
        return resp

    @classmethod
    def search_bumen(cls):
        autu = get_new_token()
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/company/department/" + a,
                            headers={"Authorization": autu })
        return resp

    @classmethod
    def delete_bumen(cls):
        autu = get_new_token()
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/company/department/" + a,
                               headers={"Authorization": autu })
        return resp
